<template>
  <header id="header">
    <a href class="logo">
      <img src="../../../static/m_img/h_l.png" alt>
    </a>
    <Form action v-model="searchForm" class="search">
      <span class="selectCity" @click="handleCityShow">
        <b class="ellipsis-1">{{area.city}}</b>
        <i class="icon_xl">1</i>
      </span>
      <Input placeholder="请输入内容" v-model="searchForm.keyWords">
        <i slot="prefix" class="el-input__icon el-icon-search"></i>
      </Input>
    </Form>
    <div class="downImg">
      <router-link to="/DownLoad">
        <img src="../../../static/m_img/h_xz.png" alt>
      </router-link>
    </div>
    <v-city
      :cityShow="cityShow"
      :title="title"
      ref="cityList"
      v-on:listenToChildEvent="showmsgformchild"
    ></v-city>
  </header>
</template>
<script>
import { Form, Input } from "element-ui";
import vCity from "./City";
import VueEvent from "../../assets/js/VueEvent.js";
export default {
  data() {
    return {
      panelShow: false,
      searchForm: {
        keyWords: ""
      },
      cityShow: false,
      title: "选择车辆所在地",
      area: {
        city: "镇江市",
        district: "润州区"
      }
    };
  },
  components: {
    Form,
    Input,
    vCity
  },
  props: {
    navIndex: {
      type: Number,
      require: true,
      default: 0
    }
  },
  methods: {
    handleCityShow() {
      this.cityShow = true;
    },
    showmsgformchild: function(data) {
      this.cityShow = data;
      if (
        this.$refs.cityList.curCityName == "" &&
        this.$refs.cityList.curProvinceName !== ""
      ) {
        this.area.city = this.$refs.cityList.curProvinceName;
      } else if (this.$refs.cityList.curCityName !== "") {
        this.area.city = this.$refs.cityList.curCityName;
      }
    },
    // 获取当前省份城市
    getPositionCity() {
      var geolocation = new BMap.Geolocation();
      var gc = new BMap.Geocoder();
      var that = this;
      geolocation.getCurrentPosition(function(r) {
        if (this.getStatus() == BMAP_STATUS_SUCCESS) {
          var pt = r.point;
          gc.getLocation(pt, function(rs) {
            var addComp = rs.addressComponents;
            var province = addComp.province;
            var district = addComp.district;
            var city = addComp.city;
            if (province != "" && city != "") {
              that.area.city = city;
              that.area.district = district;
              // that.form.provinceFrom = province;
              setCookie("cityDw", city);
              setCookie("districtDw", district);
              setCookie("provinceDw", province);
            }
          });
        }
      });
    },
    emitCity() {
      VueEvent.$emit("to-business", [this.area.city,this.area.district]);
    },
    getArea() {
      this.area.city = getCookie("cityDw");
      this.area.district = getCookie("districtDw");
     
    }
  },
  created() {
    this.getArea();
    this.getPositionCity();
    this.emitCity();
  }
};
</script>
<style type="text/css" lang='scss'>
#header {
  position: absolute;
  width: 100%;
  color: #fff;
  height: 44px;
  padding: 0 2%;
  background-color: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 999;
  .logo {
    width: 12%;
    display: flex;
    align-items: center;
    img {
      width: 100%;
    }
  }
  .search {
    display: flex;
    width: 70%;
    height: 31px;
    justify-content: space-between;
    align-items: center;
    .selectCity {
      display: flex;
      align-items: center;
      width: 30%;
      b {
        width: 60%;
        font-weight: normal;
      }
      .icon_xl {
        background: url(../../../static/m_img/h_x.png) center center no-repeat;
        text-indent: -999px;
        width: 10px;
        display: inline-block;
      }
    }
    .el-input {
      width: 80%;
      font-size: 1rem;
      height: 31px;
      .el-input__inner {
        width: 100%;
        height: 31px;
        padding-left: 28px;
      }
      .el-input__icon {
        line-height: 31px;
      }
      .el-icon-search:before {
        font-size: 1.166667rem;
        color: #0098ff;
      }
    }
  }
  img {
    width: 60%;
  }
  .downImg {
    text-align: right;
  }
}
</style>


